﻿using System;
using System.Collections.Generic;
using System.Linq;
using NTTDATA.BEENChina.ResultCertification.Config;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Date
{
    [Serializable]
    [VerfityAttribute(Id = "VerfityRq0235", Name = "第一行日期检证2", CategoryType = EnumCategoryType.日期, Model = true)]
    public class VerfityRq0235 : VerfityOneResult
    {
        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = check(result);

            if (bresult)
            {
                System.Console.WriteLine("VerfityRq0235");
                System.Console.WriteLine(Name);
            }

            return bresult;
        }

        private bool check(List<List<string>> result)
        {
            if (result == null || result.Count == 0)
            {
                return false;
            }
            
            //第一行不为空
            if (result[0].Any(o => !string.IsNullOrEmpty(string.Join("", o.Split(new char[] { '/' })))))
            {
                return false;
            }

            

            foreach (var  rowResult in result)
            {
                int rowCount = rowResult.Count;
                int emptyCount =  EmptyColumnCount(rowResult);

                if (rowCount != emptyCount)
                {
                    return true;
                }
            }

            return false;

            //List<string> dateFormatParts = ChildImageObject.CategorySetting.DataFormat.Split(new char[] { '/' }).ToList();
            ////年月的位置
            //int yyIndex = dateFormatParts.IndexOf("yy");
            //int MMIndex = dateFormatParts.IndexOf("MM");
            //if (yyIndex == -1 || MMIndex == -1)
            //{
            //    return false;
            //}
            ////如果录入结果中，年或者月不为空，则抽出。 
            //return result.SelectMany(o => o).Any(o => {
            //    string[] splitPart = o.Split(new char[] { '/' });
            //    return (  ( splitPart.Length > yyIndex && !string.IsNullOrEmpty(splitPart[yyIndex]) ) 
            //              || (splitPart.Length > MMIndex && !string.IsNullOrEmpty(splitPart[MMIndex]))  );
            //});
        }
    }
}
